package mainPackage;

import java.awt.Desktop;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import structurePackage.Donnee;
import structurePackage.Noeud;
import erlangToJsPackage.Generator;

public class TestNodeToJs {

	/** Méthode pour tester l'affichage dans le javaScript **/
	public static void creationNoeuds(){
		ArrayList<Noeud> nodes = new ArrayList<Noeud>();
		Noeud bob = new Noeud("bob");
		Noeud tata = new Noeud("tata");
		Noeud anna = new Noeud("anna");
		Noeud toto = new Noeud("toto");
		Noeud lea = new Noeud("lea");
		bob.donnees.add(new Donnee("a","aaaaa"));
		bob.donnees.add(new Donnee("b","bbbbb"));
		nodes.add(bob);
		nodes.add(tata);
		nodes.add(anna);
		nodes.add(toto);
		nodes.add(lea);

		if(java.awt.Desktop.isDesktopSupported()){
			System.out.println("DeskTop Supported");
			Generator g = new Generator(nodes);
			String page = g.toHtml();

			try {
				PrintWriter pw = new PrintWriter(new FileWriter("out.html"));
				pw.println(page);
				pw.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}

			try {
				Desktop.getDesktop().open(new File("out.html"));
			} catch (IOException e) {
				//e.printStackTrace();
			}
		}else {
			System.out.println("DeskTop not Supported");
		}
	}
}